Skip to content

feat(broker): PreToolUse enforcers gate-egress + gate-fs (Pillar 3 step 4) - #305

Merged
sandstream merged 1 commit into
mainfrom
claude/web-kit-status-sync-p6fg9a
Jul 10, 2026
Merged

sandstream merged 1 commit into
mainfrom
claude/web-kit-status-sync-p6fg9a

Conversation

@sandstream

Copy link
Copy Markdown
Owner

Description

Step 4 of the Pillar 3 exec-broker — the first enforced surface. Two PreToolUse gates in the proven gate-bash/gate-env mold that mediate the agent's actual pending tool calls against the signed [scope]/RoE via brokerScope (fail-closed). This is the North Star's advisory→enforced shift made concrete: an autonomous agent's network targets and file writes are now blockable at exec time, gated on a cryptographically attributable RoE.

Type of Change

  • New feature (non-breaking change that adds functionality)

Related Issues

Changes Made

  • src/broker/extract.ts — pure, conservative network-target extraction: only explicit http(s):// URLs (WHATWG-parsed, hostname only). A bare hostname in a command is ambiguous and is never guessed — honest limitation, documented.
  • src/commands/gate.ts:
    • kit gate-egress — a pending Bash command's network targets must all be inside the signed [scope].egress. No verified scope (unsigned / tampered / missing) ⇒ a wired gate grants nothing — all network targets denied with an honest, actionable reason. Off-scope ⇒ exit 2.
    • kit gate-fs — a pending Write/Edit must target a path inside the signed [scope].fs (traversal-safe; default project root). Same fail-closed posture.
    • Every deny leaves a best-effort audit entry (logAuditEvent; a missing .kit.toml/audit backend never changes the verdict — the deny is the safe outcome). Cline stdout-JSON contract supported like the other gates.
    • Unparseable harness envelopes fail open (the envelope comes from the agent harness, not the model — never break the agent on garbage); the scope decisions themselves stay fail-closed.
  • src/cli.ts — gate-egress / gate-fs registry entries (experimental); contracts/public-surface.json regenerated.

Testing

Test Coverage

  • Added new tests (15)
  • All tests pass (npm test) — full suite 2700 pass / 0 fail (2685 baseline + 15)

Manual Testing

  1. npx tsc --noEmit → clean; npx eslint src → 0 errors.
  2. npm run build && node scripts/gen-public-surface.mjs && node scripts/test.mjs → 2700 pass, 0 fail.
  3. The 9 gate tests are subprocess integration tests: they spawn the real compiled CLI with hook payloads on stdin in a temp project — exactly how an agent harness runs the gate — and assert exit 0 (allow) / exit 2 (deny): in-scope allow, off-scope deny, deny-all on unsigned/tampered scope, traversal escape, non-network/non-write pass-through.

Breaking Changes

None / N/A — new opt-in gates; nothing is wired automatically.

Checklist

  • All new code has test coverage
  • All tests pass locally (npm test)
  • No new warnings or errors introduced
  • No hardcoded secrets or sensitive data
  • Code has been self-reviewed

Performance Impact

  • No performance impact — the gates run only when wired as PreToolUse hooks; one profile read + offline signature verify per gated call

Reviewer Notes

The deliberate asymmetry to review: fail-open on the envelope, fail-closed on the scope. An unparseable stdin envelope is a harness/config artifact (the model cannot shape it), so it must not brick the agent — same posture as gate-bash/gate-env. But once a network target or file write is identified, the decision is strictly fail-closed: wiring the gate is the opt-in, and without a verified scope it grants nothing. gate-secret is deliberately absent — secret-scoped env belongs at exec time inside withGovernance (step 5), not in a PreToolUse hook, and a stub here would be false enforcement. Remaining: step 5 (scope step in withGovernance) + agent-config wiring convenience.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DbF4MFePXWNCd4dxBQvqH2


Generated by Claude Code

…ep 4)

The first ENFORCED surface of the exec-broker (design: pillar3-exec-broker-5.0.md §3.3):
two PreToolUse gates in the gate-bash/gate-env mold that mediate the agent's actual pending
tool calls against the SIGNED [scope]/RoE via brokerScope (fail-closed).

- broker/extract.ts: pure, conservative network-target extraction — only explicit http(s)
  URLs (WHATWG-parsed); a bare hostname in a command is ambiguous and never guessed.
- kit gate-egress: a pending Bash command's network targets must all be inside the signed
  [scope].egress. No verified scope (unsigned/tampered/missing) => a wired gate grants
  NOTHING — all network targets denied with an honest reason. Off-scope => exit 2.
- kit gate-fs: a pending Write/Edit must target a path inside the signed [scope].fs
  (traversal-safe, default project root). Same fail-closed posture.
- Every deny leaves a best-effort audit entry (logAuditEvent; a missing .kit.toml or audit
  backend never changes the verdict — the deny is the safe outcome). Cline stdout-JSON
  contract supported like the other gates. Unparseable HARNESS envelopes fail open (the
  model can't shape the envelope; never break the agent on garbage) — the scope decisions
  themselves stay fail-closed.
- Registry entries (experimental) + public-surface regenerated.

Tests: 6 pure extraction fixtures + 9 SUBPROCESS integration tests spawning the real compiled
CLI with hook payloads on stdin (allow in-scope, exit-2 deny off-scope, deny-all on unsigned/
tampered scope, traversal escape, pass-through for non-network/non-write calls).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbF4MFePXWNCd4dxBQvqH2
@github-actions

Copy link
Copy Markdown

✅ Docker image built successfully

  • CLI image: docker.io/sandstream/kit:test

@sandstream
sandstream merged commit 540e835 into main Jul 10, 2026
18 checks passed
@sandstream
sandstream deleted the claude/web-kit-status-sync-p6fg9a branch July 10, 2026 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants